﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;

namespace TaobaoERP.Core.Common
{
    public static class Utils
    {
        #region Private members

        private static string _RelativeWebRoot;
        private static string _ThemesRoot;

        #endregion

        #region Public members

        public static string RelativeWebRoot
        {
            get
            {
                if (_RelativeWebRoot == null)
                    _RelativeWebRoot = VirtualPathUtility.ToAbsolute(ConfigurationManager.AppSettings["CNdotnet.Ezsocio.VirtualPath"]);

                return _RelativeWebRoot;
            }
        }

        public static string ThemesRoot
        {
            get
            {
                if (_ThemesRoot == null)
                    _ThemesRoot = VirtualPathUtility.ToAbsolute(ConfigurationManager.AppSettings["CNdotnet.Ezsocio.ThemesPath"]);
                return _ThemesRoot;
            }
        }

        public static Uri AbsoluteWebRoot
        {
            get
            {
                HttpContext context = HttpContext.Current;
                if (context == null)
                    throw new Exception("当前HttpContext为空");

                if (context.Items["absoluteurl"] == null)
                    context.Items["absoluteurl"] = new Uri(context.Request.Url.GetLeftPart(UriPartial.Authority) + RelativeWebRoot);

                return context.Items["absoluteurl"] as Uri;
            }
        }

        public static string DatabaseConnectionString
        {
            get
            {
                return ConfigurationManager.ConnectionStrings["CNdotnet.Ezsocio.DBConnection"].ConnectionString;
            }
        }
        #endregion
    }
}
